<template>
  <el-form ref="formRef" :model="form" label-width="120px" size="default">
    <el-form-item>
      <h2>
        <el-link type="warning">捞出12小时外籍人员已出结果脚本</el-link>
      </h2>
    </el-form-item>
    <el-form-item label="时间范围：">
      <el-date-picker
        v-model="form.timeArr"
        type="datetimerange"
        :editable="false"
        format="YYYY-MM-DD HH:mm:ss"
        value-format="YYYY-MM-DD HH:mm:ss"
        range-separator="至"
        start-placeholder="开始时间"
        end-placeholder="结束时间"
      >
      </el-date-picker>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">生成脚本</el-button>
      <el-button type="default" @click="exportFile">导出文件</el-button>
    </el-form-item>
    <el-form-item label="脚本：">
      <el-input autosize type="textarea" v-model="form.scriptString" readonly></el-input>
    </el-form-item>
  </el-form>
</template>

<script setup>
import { ref, reactive } from "vue";
import { format } from "./js/timeFromat";
import saveAs from "./js/FileSaver";
// do not use same name with ref
const form = reactive({
  timeArr: [],
  // 脚本
  scriptString: ""
});

const exportFile = () => {
  let str = new Blob([form.scriptString], {
    type: "text/plain;charset=utf-8"
  });
  saveAs(str, `捞出12小时外籍人员已出结果脚本.txt`);
};

const onSubmit = () => {
  let code = form.tubeCode;
  form.scriptString = `环境：太极政务云
数据库地址：192.159.107.33:2000
数据库名：nat_admin

打印奥运报告  姓名  性别 出生日期  CT值  生成报告的字段   涉奥的外籍人士   报告出一个excel表头

姓名	性别	出生日期	国家或地区	注册号	证件号	采样日期和时间	标本类型	检测方法	结果	报告日期和时间	N基因CT值	ORF1ab基因CT值	检测机构	检测人	审核人	日期	采集点

请执行下面脚本：
print("姓名,性别,出生日期,国家或地区,注册号,证件号,采样日期和时间,标本类型,检测方法,结果,报告日期和时间,N基因CT值,ORF1ab基因CT值,检测机构,检测人,审核人,日期,采样点名称");
db.nat_appo_check_relation.find({"sam_time":{"$gte":"${form.timeArr[0]}","$lte":"${form.timeArr[1]}"},"appo_status":6}).forEach(function(document){
if(document.checked_person_card_number.length != 18){
var registerObj = db.olympic_register_card_person.findOne({"card_number":document.checked_person_card_number});
if(registerObj != null){
var n_ct_value = "";
var orf1_ab_ct_value = "";
if(document.n_ct_value != null){
n_ct_value = document.n_ct_value
}
if(document.orf1_ab_ct_value != null){
orf1_ab_ct_value = document.orf1_ab_ct_value
}
print(registerObj.name+","+registerObj.sex+","+registerObj.birthday+","+registerObj.country_region+","+registerObj.register_id+","+registerObj.card_number+","+
document.sam_time+","+document.sample_type+",实时PCR荧光法,"+document.check_result+","+document.audit_time+","+
n_ct_value+","+orf1_ab_ct_value+","+document.check_inst_name+","+document.check_user_name+","+document.auditer+","+document.audit_time+","+document.sample_point_name)
}
}
});`;
};
</script>

<style>
.input-width {
  width: 500px;
}
</style>
